<?php declare(strict_types=1);
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/5/11
 * Time: 16:27
 */

namespace App\Aspect;

use Swoft\Aop\Annotation\Mapping\Aspect;
use Swoft\Aop\Annotation\Mapping\Before;
use Swoft\Aop\Annotation\Mapping\AfterThrowing;
use Swoft\Aop\Annotation\Mapping\PointExecution;
use Swoft\Aop\Point\JoinPoint;
use EasyWeChat\Factory;
use Swoft\Http\Message\Request;
/**
 * Class OpenWechatAspect
 * @package App\Aspect
 * @Aspect()
 * @PointExecution(include={"OpenWechatController::index"})
 */

class OpenWechatAspect
{
    /**
     * @Before()
     */
   public function before(JoinPoint $joinPoint)
   {

       $config = [
           'app_id'   => 'wx51492bb3682453bc',
           'secret'   => '7809070a8cf7686f569a9f5ae528000e',
           'token'    => '7eaf442sf2d0688fg03951c3ee84438bc49',
           'aes_key'  => '8eh438bc49dr63f4sdd4fedfsdfee59dm50frhlo2zg'
       ];
       $this->openPlatform = Factory::openPlatform($config);

       $args = $joinPoint->getArgs();
       /**
        * @var Request $request
        */
       $request = $args[0];
       $param = $request->getQueryParams();

       print_r($request->getQueryParams());
   }

    /**
     * @AfterThrowing()
     * @return mixed
     * @throws \Throwable
     */

    public  function  afterThrowing($id){

        echo "捕获到异常调用";

    }
}
